DESCRIPTION
We are installing the ‘openai’ for r package and setting up the API key so that you can interact with openai engines while in foreign IDE (RStudio). There is also a package called ‘gptstudio’ for addins that connect with the OpenAi engines directly in RStudio and we will check that out later.
Before or After you install the packages you must create an account with OpenAi so you can receive a personal API Key and access the gpt engines. Link: OpenAi-Account-Registration
SET UP
‘openai’ package use: API key authentication-global set up
Credit this portion to github user: irudnyts, who develops packages for R
Link To github repo: irudnyts/openai package documentation
## replace with your own API key
Sys.setenv(OPENAI_API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')This is a global setup, if you want to make it project based use ‘.Renviron’ file method and do a quick tutorial search.
‘openai’ package examples
NOTE: Anything you send as an API request to OpenAi is being shared with them, Remember to keep prompts away from containing PII, sensitive information, etc.
Below, you can see the ai generated text to image after pasting the output URL in a browser and making sure the image is the one we want and the prompt does not need to be changed. From the URL I saved the image file and then linked it here and I will do the same with the second example.
NOTE: I did try just inserting the URL but the authentication token that uses my API key was timing out after a certain amount of time so I just saved the image file from the URL and inserted the file that way instead of just a URL.
## run this code in the console and it will return a url with the result of your query.
create_image("An astronaut-horse eating pizza on the beach")ai-generated-text-to-image-“An astronaut-horse eating pizza on the beach”
## run this code in the console and it will return a url with the result of your query.
## you can change the prompt and request another query if the image is not what you want.
create_image("The Yorkie dog pirate, Captain Dog, eating a sushi roll with chopsticks")ai-generated-text-to-image-“The Yorkie dog pirate, Captain Dog, eating a sushi roll with chopsticks”
‘gptstudio’ package use: Addins>ChatGpt
Credit this portion to github user: MichelNivard, who develops packages for R
Link To github repo: MichelNivard/gptstudio package documentation
Now I am going to use the package ‘gptstudio’ to set up some addins. The package should be installed and loaded in environment already and the API key should also already be set.
Click the ‘Addins’ drop down from Toolbar, you should see the ‘gptstudio’ package addins in there. Feel free to set up some keyboard shortcuts on any functions you plan to use frequently.
Some examples of use. ChatGPT in RStudio
- Addins > GPTSTUDIO > ChatGPT
- Type your question.
- Click “Chat”
- Ask more questions